package com.agilegroup.crm.ui.fragments;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockDialogFragment;
import com.agilegroup.crm.R;

public class AboutDialogFragment extends SherlockDialogFragment{

	private TextView txtAbout;
	
	private static String VersionName(Context context) {
	    try {
	      return context.getPackageManager().getPackageInfo(context.getPackageName(),0).versionName;
	    } catch (NameNotFoundException e) {
	      return "Unknown";
	    }
	  }
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater li = LayoutInflater.from(getActivity());
		View promptsView = li.inflate(R.layout.about_box, null);
		builder.setView(promptsView);
        builder.setTitle(getResources().getString(R.string.activity_dialog))
               .setPositiveButton(R.string.btnAbout, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                      dismiss();
                   }
               });
        txtAbout = (TextView)promptsView.findViewById(R.id.aboutVersion);
        txtAbout.setText("Version "+VersionName(getActivity()));
        return builder.create();
	}
}